#ifndef SOBJC_COMMONS_DEFINES_H
#define SOBJC_COMMONS_DEFINES_H

#include <sobjc-commons/port.h>

#ifdef __cplusplus
extern "C" {
#ifdef 0
} /* for editor */
#endif
#endif 

#define ALLOC_N(type,n)          (type*)objc_malloc(sizeof(type)*n)
#define ALLOC(type)              (type*)objc_malloc(sizeof(type))
#define ALLOC_ATOM_N(type,n)     (type*)objc_malloc_atomic(sizeof(type)*n)
#define ALLOC_ATOM(type)         (type*)objc_malloc_atomic(sizeof(type))
#define REALLOC_N(var,type,n)    ((var)=(type*)objc_realloc((var),sizeof(type)*n))
#define REALLOC(var,type)        ((var)=(type*)objc_realloc((var),sizeof(type)))

#define MEMZERO(p,type,n)        memset((p), 0, sizeof(type)*(n))
#define MEMCPY(p1,p2,type,n)     memcpy((p1), (p2), sizeof(type)*(n))
#define MEMMOVE(p1,p2,type,n)    memmove((p1), (p2), sizeof(type)*(n))
#define MEMCMP(p1,p2,type,n)     memcmp((p1), (p2), sizeof(type)*(n))

#ifdef  __va_copy
#define VA_COPY(var,list)        __va_copy(var, list)
#else
#define VA_COPY(var,list)        var = list
#endif

#define STRCPY(var,s)                   \
  do {                                  \
    (var) = ALLOC_N(char, strlen(s)+1); \
   strcpy((var), (s));                  \
  } while (0)
#define STREQ(a,b)               (strcmp((a), (b)) == 0)
#define STREQ_N(a,b,n)           (strncmp((a), (b), n) == 0)

#define MIN(a,b)                 (((a)<(b))?(a):(b))
#define MAX(a,b)                 (((a)>(b))?(a):(b))

#ifdef __cplusplus
}
#endif
#endif /* SOBJC_COMMONS_DEFINES_H */

